/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Divisi;

/**
 *
 * @author tashiba
 */
public class DivisiTableModel extends AbstractTableModel {

    private List<Divisi> div = new ArrayList<Divisi>();

    public DivisiTableModel(List<Divisi> divisi) {
        this.div = divisi;
    }

    public void deleteDivisi(int row) {
        div.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateDivisi(int row, Divisi divisi) {
        div.set(row, divisi);
        fireTableRowsUpdated(row, row);
    }

    public void addDivisi(Divisi divisi) {
        div.add(divisi);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    @Override
    public int getRowCount() {
        return div.size();
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Divisi b = div.get(rowIndex);
        switch (columnIndex) {
             case 0:
                return b.getIdDivisi();
            case 1:
                return b.getNamaDivisi();

            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
             case 0:
                return "Id Divisi";
            case 1:
                return "Nama Divisi";
            default:
                return "";
        }
    }
}

